Skip to content

[WP] Add is_session_leader field to process events#48307

Closed
loresuso wants to merge 2 commits intoDataDog:mainfrom
loresuso:loresuso/add-is-session-leader
Closed

[WP] Add is_session_leader field to process events#48307
loresuso wants to merge 2 commits intoDataDog:mainfrom
loresuso:loresuso/add-is-session-leader

Conversation

@loresuso
Copy link
Copy Markdown
Contributor

@loresuso loresuso commented Mar 24, 2026

Add a new boolean field is_session_leader to CWS process events that indicates whether a process is a session leader (PID == SID).

The session ID is read from the kernel via:

task->signal->pids[PIDTYPE_SID]->numbers[0].nr

and compared against the process tgid. Two new kernel offset constants are introduced (task_struct_signal_offset, signal_struct_pids_offset) resolved via BTF at runtime.

The field is exposed in SECL as process.is_session_leader and propagates to all process-related event types (exec, exit, signal, ptrace, etc.).

Example of condition where this could be useful: spawning of a session leader shell from a not known binary (e.g. a shell given by the shell command of a sliver C2 implant

exec.file.name in ["sh", "bash", "zsh", "dash"] &&
  process.is_session_leader &&
  process.parent.file.name not in ["sshd", "login", "systemd", "init", "su", "sudo", "cron", "tmux: server", "screen", "agetty"]

@loresuso loresuso marked this pull request as ready for review March 25, 2026 11:07
@loresuso loresuso requested review from a team as code owners March 25, 2026 11:07
@loresuso loresuso force-pushed the loresuso/add-is-session-leader branch from 5705414 to d93f625 Compare March 25, 2026 11:10
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 25, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5705414150

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pkg/security/ebpf/c/include/hooks/exec.h Outdated
@loresuso loresuso force-pushed the loresuso/add-is-session-leader branch from d93f625 to 71464db Compare March 25, 2026 12:03
Comment thread pkg/security/ebpf/c/include/hooks/exec.h Outdated
Comment thread pkg/security/ebpf/c/include/structs/events_context.h Outdated
@loresuso loresuso force-pushed the loresuso/add-is-session-leader branch 2 times, most recently from 6c88473 to d56a9f8 Compare March 25, 2026 14:01
@safchain safchain added category/improvement qa/done QA done before merge and regressions are covered by tests labels Mar 25, 2026
@safchain safchain added this to the 7.79.0 milestone Mar 25, 2026
@loresuso loresuso added the changelog/no-changelog No changelog entry needed label Mar 25, 2026
@loresuso
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@loresuso
Copy link
Copy Markdown
Contributor Author

recheck

@loresuso loresuso force-pushed the loresuso/add-is-session-leader branch 3 times, most recently from 43addd7 to b704d29 Compare March 26, 2026 14:33
@loresuso loresuso force-pushed the loresuso/add-is-session-leader branch from b704d29 to 0bef8b2 Compare March 30, 2026 11:02
@loresuso
Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 Bot commented Mar 30, 2026

View all feedbacks in Devflow UI.

2026-03-30 11:45:44 UTC ℹ️ Start processing command /merge


2026-03-30 11:45:46 UTC ❌ MergeQueue

PR already in the queue with status waiting

Add a new boolean field `is_session_leader` to CWS process events that
indicates whether a process is a session leader (PID == SID).

The session ID is read from the kernel via:
  task->signal->pids[PIDTYPE_SID]->numbers[0].nr

and compared against the process tgid. Two new kernel offset constants
are introduced (task_struct_signal_offset, signal_struct_pids_offset)
resolved via BTF at runtime.

The field is exposed in SECL as process.is_session_leader and propagates
to all process-related event types (exec, exit, signal, ptrace, etc.).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@loresuso loresuso force-pushed the loresuso/add-is-session-leader branch from 0bef8b2 to 56ea633 Compare March 31, 2026 15:39
- Use bitfield for is_kworker and is_session_leader in process_context_t,
  keeping the struct at 40 bytes instead of growing to 48
- Restore the original if/else in exec handler cookie update

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@loresuso loresuso force-pushed the loresuso/add-is-session-leader branch from 56ea633 to 68c957f Compare March 31, 2026 15:42
@loresuso
Copy link
Copy Markdown
Contributor Author

loresuso commented Apr 1, 2026

closing in favor of a non-fork PR

@loresuso loresuso closed this Apr 1, 2026
if (sid_pid) {
u32 sid = 0;
bpf_probe_read_kernel(&sid, sizeof(sid), (void *)sid_pid + get_pid_numbers_offset());
fork_entry->is_session_leader = (sid != 0 && sid == tgid) ? 1 : 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it's not better to send the sid to the user space and then add the boolean field. We might use the sid at some point no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category/improvement changelog/no-changelog No changelog entry needed qa/done QA done before merge and regressions are covered by tests team/agent-security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants